﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Xml;
using System.IO;

/// <summary>
/// Summary description for Common
/// </summary>
public class CommonLog
{	
    public DataTable GetLogs()
    {
        DataTable dt = new DataTable();
        return dt;
    }
    //For the GeneralLog.
    public void SetLogs(string id, string userid, string LogType, string LogMsg, string PageName, string IPAddress, string DateTime)
    {
        string date = System.DateTime.Now.ToString(string.Format("dd-MMM-yyyy"));
        string path = HttpContext.Current.Server.MapPath("~/XML/");
        string fileName = string.Empty;
        string FileNames = path +"Log_General_"+ date + ".xml";
        DirectoryInfo dir = new DirectoryInfo(path);
        FileInfo[] fileList = dir.GetFiles("Log_General_*.xml", System.IO.SearchOption.AllDirectories);
        if (fileList.LongLength == 0)
        {
            XmlTextWriter xmlWriter = new XmlTextWriter(FileNames, System.Text.Encoding.UTF8);
            xmlWriter.Formatting = Formatting.Indented;
            xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
            xmlWriter.WriteStartElement("LogsDetails");
            xmlWriter.Close();

            XmlDocument xmldoc = new XmlDocument();
            //xmldoc.Load(Server.MapPath("~/XML/EmployeEdit" + DateTime.Now.ToShortDateString() + ".xml"));
            //xmldoc.Load("c:\\firstXML" + DateTime.Now.ToString(string.Format("dd-MMM-yyyy")) + ".xml");
            xmldoc.Load(FileNames);
            XmlElement parentNode = xmldoc.CreateElement("log");

            XmlElement Tid = xmldoc.CreateElement("id");
            XmlElement Tuserid = xmldoc.CreateElement("userid");
            XmlElement Tlogtype = xmldoc.CreateElement("logtype");
            XmlElement Tlogmesg = xmldoc.CreateElement("logmesg");
            XmlElement Tpagename = xmldoc.CreateElement("pagename");
            XmlElement Tipaddr = xmldoc.CreateElement("ipaddr");
            XmlElement Tdatetime = xmldoc.CreateElement("datetime");

            Tid.InnerText = id.ToString();
            Tuserid.InnerText = userid.ToString();
            Tlogtype.InnerText = LogType.ToString();
            Tlogmesg.InnerText = LogMsg.ToString();
            Tpagename.InnerText = PageName.ToString();
            Tipaddr.InnerText = IPAddress.ToString();
            Tdatetime.InnerText =System.DateTime.Now.ToString(string.Format("dd/MM/yyyy hh:mm:ss"));

            parentNode.AppendChild(Tid);
            parentNode.AppendChild(Tuserid);
            parentNode.AppendChild(Tlogtype);
            parentNode.AppendChild(Tlogmesg);
            parentNode.AppendChild(Tpagename);
            parentNode.AppendChild(Tipaddr);
            parentNode.AppendChild(Tdatetime);

            xmldoc.DocumentElement.AppendChild(parentNode);
            xmldoc.Save(FileNames);
        }
        else
        {
            var fileCount = from fileNew in fileList where fileNew.Name.Equals("Log_General_"+date + ".xml") select fileNew.Name;
            if (fileCount.Count() == 1)
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(FileNames);
                XmlElement parentNode = xmldoc.CreateElement("log");

                XmlElement Tid = xmldoc.CreateElement("id");
                XmlElement Tuserid = xmldoc.CreateElement("userid");
                XmlElement Tlogtype = xmldoc.CreateElement("logtype");
                XmlElement Tlogmesg = xmldoc.CreateElement("logmesg");
                XmlElement Tpagename = xmldoc.CreateElement("pagename");
                XmlElement Tipaddr = xmldoc.CreateElement("ipaddr");
                XmlElement Tdatetime = xmldoc.CreateElement("datetime");

                Tid.InnerText = id.ToString();
                Tuserid.InnerText = userid.ToString();
                Tlogtype.InnerText = LogType.ToString();
                Tlogmesg.InnerText = LogMsg.ToString();
                Tpagename.InnerText = PageName.ToString();
                Tipaddr.InnerText = IPAddress.ToString();
                Tdatetime.InnerText = System.DateTime.Now.ToString(string.Format("dd/MM/yyyy hh:mm:ss"));

                parentNode.AppendChild(Tid);
                parentNode.AppendChild(Tuserid);
                parentNode.AppendChild(Tlogtype);
                parentNode.AppendChild(Tlogmesg);
                parentNode.AppendChild(Tpagename);
                parentNode.AppendChild(Tipaddr);
                parentNode.AppendChild(Tdatetime);

                xmldoc.DocumentElement.AppendChild(parentNode);
                xmldoc.Save(FileNames);
            }
            else
            {
                XmlTextWriter xmlWriter = new XmlTextWriter(FileNames, System.Text.Encoding.UTF8);
                xmlWriter.Formatting = Formatting.Indented;
                xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
                xmlWriter.WriteStartElement("LogsDetails");
                xmlWriter.Close();

                XmlDocument xmldoc = new XmlDocument();
                //xmldoc.Load(Server.MapPath("~/XML/EmployeEdit" + DateTime.Now.ToShortDateString() + ".xml"));
                //xmldoc.Load("c:\\firstXML" + DateTime.Now.ToString(string.Format("dd-MMM-yyyy")) + ".xml");
                xmldoc.Load(FileNames);
                XmlElement parentNode = xmldoc.CreateElement("log");

                XmlElement Tid = xmldoc.CreateElement("id");
                //XmlAttribute attributeID = xmldoc.CreateAttribute("");
                XmlElement Tuserid = xmldoc.CreateElement("userid");
                XmlElement Tlogtype = xmldoc.CreateElement("logtype");
                XmlElement Tlogmesg = xmldoc.CreateElement("logmesg");
                XmlElement Tpagename = xmldoc.CreateElement("pagename");
                XmlElement Tipaddr = xmldoc.CreateElement("ipaddr");
                XmlElement Tdatetime = xmldoc.CreateElement("datetime");

                Tid.InnerText = id.ToString();
                Tuserid.InnerText = userid.ToString();
                Tlogtype.InnerText = LogType.ToString();
                Tlogmesg.InnerText = LogMsg.ToString();
                Tpagename.InnerText = PageName.ToString();
                Tipaddr.InnerText = IPAddress.ToString();
                Tdatetime.InnerText = System.DateTime.Now.ToString(string.Format("dd/MM/yyyy hh:mm:ss"));

                parentNode.AppendChild(Tid);
                parentNode.AppendChild(Tuserid);
                parentNode.AppendChild(Tlogtype);
                parentNode.AppendChild(Tlogmesg);
                parentNode.AppendChild(Tpagename);
                parentNode.AppendChild(Tipaddr);
                parentNode.AppendChild(Tdatetime);

                xmldoc.DocumentElement.AppendChild(parentNode);
                xmldoc.Save(FileNames);
            }
        }
    }
    //For the Item Master
    public void SetItemLogs(string id, string userid, string LogType, string LogMsg, string PageName, string IPAddress, string DateTime)
    {
        string date = System.DateTime.Now.ToString(string.Format("dd-MMM-yyyy"));
        string path = HttpContext.Current.Server.MapPath("~/XML/");
        string FileNames = path + "Log_Item_" + date + ".xml";
        string fileName = string.Empty;
        DirectoryInfo dir = new DirectoryInfo(path);
        FileInfo[] fileList = dir.GetFiles("Log_Item_*.xml", System.IO.SearchOption.AllDirectories);
        if (fileList.LongLength == 0)
        {
            XmlTextWriter xmlWriter = new XmlTextWriter(FileNames, System.Text.Encoding.UTF8);
            xmlWriter.Formatting = Formatting.Indented;
            xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
            xmlWriter.WriteStartElement("LogsDetails");
            xmlWriter.Close();

            XmlDocument xmldoc = new XmlDocument();
            //xmldoc.Load(Server.MapPath("~/XML/EmployeEdit" + DateTime.Now.ToShortDateString() + ".xml"));
            //xmldoc.Load("c:\\firstXML" + DateTime.Now.ToString(string.Format("dd-MMM-yyyy")) + ".xml");
            xmldoc.Load(FileNames);
            XmlElement parentNode = xmldoc.CreateElement("log");

            XmlElement Tid = xmldoc.CreateElement("id");
            XmlElement Tuserid = xmldoc.CreateElement("userid");
            XmlElement Tlogtype = xmldoc.CreateElement("logtype");
            XmlElement Tlogmesg = xmldoc.CreateElement("logmesg");
            XmlElement Tpagename = xmldoc.CreateElement("pagename");
            XmlElement Tipaddr = xmldoc.CreateElement("ipaddr");
            XmlElement Tdatetime = xmldoc.CreateElement("datetime");

            Tid.InnerText = id.ToString();
            Tuserid.InnerText = userid.ToString();
            Tlogtype.InnerText = LogType.ToString();
            Tlogmesg.InnerText = LogMsg.ToString();
            Tpagename.InnerText = PageName.ToString();
            Tipaddr.InnerText = IPAddress.ToString();
            Tdatetime.InnerText = System.DateTime.Now.ToString(string.Format("dd/MM/yyyy hh:mm:ss"));

            parentNode.AppendChild(Tid);
            parentNode.AppendChild(Tuserid);
            parentNode.AppendChild(Tlogtype);
            parentNode.AppendChild(Tlogmesg);
            parentNode.AppendChild(Tpagename);
            parentNode.AppendChild(Tipaddr);
            parentNode.AppendChild(Tdatetime);

            xmldoc.DocumentElement.AppendChild(parentNode);
            xmldoc.Save(FileNames);
        }
        else
        {
            var fileCount = from fileNew in fileList where fileNew.Name.Equals("Log_Item_" + date + ".xml") select fileNew.Name;
            if (fileCount.Count() == 1)
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(FileNames);
                XmlElement parentNode = xmldoc.CreateElement("log");

                XmlElement Tid = xmldoc.CreateElement("id");
                XmlElement Tuserid = xmldoc.CreateElement("userid");
                XmlElement Tlogtype = xmldoc.CreateElement("logtype");
                XmlElement Tlogmesg = xmldoc.CreateElement("logmesg");
                XmlElement Tpagename = xmldoc.CreateElement("pagename");
                XmlElement Tipaddr = xmldoc.CreateElement("ipaddr");
                XmlElement Tdatetime = xmldoc.CreateElement("datetime");

                Tid.InnerText = id.ToString();
                Tuserid.InnerText = userid.ToString();
                Tlogtype.InnerText = LogType.ToString();
                Tlogmesg.InnerText = LogMsg.ToString();
                Tpagename.InnerText = PageName.ToString();
                Tipaddr.InnerText = IPAddress.ToString();
                Tdatetime.InnerText = System.DateTime.Now.ToString(string.Format("dd/MM/yyyy hh:mm:ss"));

                parentNode.AppendChild(Tid);
                parentNode.AppendChild(Tuserid);
                parentNode.AppendChild(Tlogtype);
                parentNode.AppendChild(Tlogmesg);
                parentNode.AppendChild(Tpagename);
                parentNode.AppendChild(Tipaddr);
                parentNode.AppendChild(Tdatetime);

                xmldoc.DocumentElement.AppendChild(parentNode);
                xmldoc.Save(FileNames);
            }
            else
            {
                XmlTextWriter xmlWriter = new XmlTextWriter(FileNames, System.Text.Encoding.UTF8);
                xmlWriter.Formatting = Formatting.Indented;
                xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
                xmlWriter.WriteStartElement("LogsDetails");
                xmlWriter.Close();

                XmlDocument xmldoc = new XmlDocument();
                //xmldoc.Load(Server.MapPath("~/XML/EmployeEdit" + DateTime.Now.ToShortDateString() + ".xml"));
                //xmldoc.Load("c:\\firstXML" + DateTime.Now.ToString(string.Format("dd-MMM-yyyy")) + ".xml");
                xmldoc.Load(FileNames);
                XmlElement parentNode = xmldoc.CreateElement("log");

                XmlElement Tid = xmldoc.CreateElement("id");
                //XmlAttribute attributeID = xmldoc.CreateAttribute("");
                XmlElement Tuserid = xmldoc.CreateElement("userid");
                XmlElement Tlogtype = xmldoc.CreateElement("logtype");
                XmlElement Tlogmesg = xmldoc.CreateElement("logmesg");
                XmlElement Tpagename = xmldoc.CreateElement("pagename");
                XmlElement Tipaddr = xmldoc.CreateElement("ipaddr");
                XmlElement Tdatetime = xmldoc.CreateElement("datetime");

                Tid.InnerText = id.ToString();
                Tuserid.InnerText = userid.ToString();
                Tlogtype.InnerText = LogType.ToString();
                Tlogmesg.InnerText = LogMsg.ToString();
                Tpagename.InnerText = PageName.ToString();
                Tipaddr.InnerText = IPAddress.ToString();
                Tdatetime.InnerText = System.DateTime.Now.ToString(string.Format("dd/MM/yyyy hh:mm:ss"));

                parentNode.AppendChild(Tid);
                parentNode.AppendChild(Tuserid);
                parentNode.AppendChild(Tlogtype);
                parentNode.AppendChild(Tlogmesg);
                parentNode.AppendChild(Tpagename);
                parentNode.AppendChild(Tipaddr);
                parentNode.AppendChild(Tdatetime);

                xmldoc.DocumentElement.AppendChild(parentNode);
                xmldoc.Save(FileNames);
            }
        }
    }
    //For Purchase
    public void SetPurchaseOrderLogs(string id, string userid, string LogType, string LogMsg, string PageName, string IPAddress, string DateTime)
    {
        string date = System.DateTime.Now.ToString(string.Format("dd-MMM-yyyy"));
        string path = HttpContext.Current.Server.MapPath("~/XML/");
        string fileName = string.Empty;
        string FileNames = path + "Log_PurchaseOrder_" + date + ".xml";
        DirectoryInfo dir = new DirectoryInfo(path);
        FileInfo[] fileList = dir.GetFiles("Log_PurchaseOrder_*.xml", System.IO.SearchOption.AllDirectories);
        if (fileList.LongLength == 0)
        {
            XmlTextWriter xmlWriter = new XmlTextWriter(FileNames, System.Text.Encoding.UTF8);
            xmlWriter.Formatting = Formatting.Indented;
            xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
            xmlWriter.WriteStartElement("LogsDetails");
            xmlWriter.Close();

            XmlDocument xmldoc = new XmlDocument();
            //xmldoc.Load(Server.MapPath("~/XML/EmployeEdit" + DateTime.Now.ToShortDateString() + ".xml"));
            //xmldoc.Load("c:\\firstXML" + DateTime.Now.ToString(string.Format("dd-MMM-yyyy")) + ".xml");
            xmldoc.Load(FileNames);
            XmlElement parentNode = xmldoc.CreateElement("log");

            XmlElement Tid = xmldoc.CreateElement("id");
            XmlElement Tuserid = xmldoc.CreateElement("userid");
            XmlElement Tlogtype = xmldoc.CreateElement("logtype");
            XmlElement Tlogmesg = xmldoc.CreateElement("logmesg");
            XmlElement Tpagename = xmldoc.CreateElement("pagename");
            XmlElement Tipaddr = xmldoc.CreateElement("ipaddr");
            XmlElement Tdatetime = xmldoc.CreateElement("datetime");

            Tid.InnerText = id.ToString();
            Tuserid.InnerText = userid.ToString();
            Tlogtype.InnerText = LogType.ToString();
            Tlogmesg.InnerText = LogMsg.ToString();
            Tpagename.InnerText = PageName.ToString();
            Tipaddr.InnerText = IPAddress.ToString();
            Tdatetime.InnerText = System.DateTime.Now.ToString(string.Format("dd/MM/yyyy"));

            parentNode.AppendChild(Tid);
            parentNode.AppendChild(Tuserid);
            parentNode.AppendChild(Tlogtype);
            parentNode.AppendChild(Tlogmesg);
            parentNode.AppendChild(Tpagename);
            parentNode.AppendChild(Tipaddr);
            parentNode.AppendChild(Tdatetime);

            xmldoc.DocumentElement.AppendChild(parentNode);
            xmldoc.Save(FileNames);
        }
        else
        {
            var fileCount = from fileNew in fileList where fileNew.Name.Equals("Log_PurchaseOrder_" + date + ".xml") select fileNew.Name;
            if (fileCount.Count() == 1)
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(FileNames);
                XmlElement parentNode = xmldoc.CreateElement("log");

                XmlElement Tid = xmldoc.CreateElement("id");
                XmlElement Tuserid = xmldoc.CreateElement("userid");
                XmlElement Tlogtype = xmldoc.CreateElement("logtype");
                XmlElement Tlogmesg = xmldoc.CreateElement("logmesg");
                XmlElement Tpagename = xmldoc.CreateElement("pagename");
                XmlElement Tipaddr = xmldoc.CreateElement("ipaddr");
                XmlElement Tdatetime = xmldoc.CreateElement("datetime");

                Tid.InnerText = id.ToString();
                Tuserid.InnerText = userid.ToString();
                Tlogtype.InnerText = LogType.ToString();
                Tlogmesg.InnerText = LogMsg.ToString();
                Tpagename.InnerText = PageName.ToString();
                Tipaddr.InnerText = IPAddress.ToString();
                Tdatetime.InnerText = System.DateTime.Now.ToString(string.Format("dd/MM/yyyy"));

                parentNode.AppendChild(Tid);
                parentNode.AppendChild(Tuserid);
                parentNode.AppendChild(Tlogtype);
                parentNode.AppendChild(Tlogmesg);
                parentNode.AppendChild(Tpagename);
                parentNode.AppendChild(Tipaddr);
                parentNode.AppendChild(Tdatetime);

                xmldoc.DocumentElement.AppendChild(parentNode);
                xmldoc.Save(FileNames);
            }
            else
            {
                XmlTextWriter xmlWriter = new XmlTextWriter(FileNames, System.Text.Encoding.UTF8);
                xmlWriter.Formatting = Formatting.Indented;
                xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
                xmlWriter.WriteStartElement("LogsDetails");
                xmlWriter.Close();

                XmlDocument xmldoc = new XmlDocument();
                //xmldoc.Load(Server.MapPath("~/XML/EmployeEdit" + DateTime.Now.ToShortDateString() + ".xml"));
                //xmldoc.Load("c:\\firstXML" + DateTime.Now.ToString(string.Format("dd-MMM-yyyy")) + ".xml");
                xmldoc.Load(FileNames);
                XmlElement parentNode = xmldoc.CreateElement("log");

                XmlElement Tid = xmldoc.CreateElement("id");
                //XmlAttribute attributeID = xmldoc.CreateAttribute("");
                XmlElement Tuserid = xmldoc.CreateElement("userid");
                XmlElement Tlogtype = xmldoc.CreateElement("logtype");
                XmlElement Tlogmesg = xmldoc.CreateElement("logmesg");
                XmlElement Tpagename = xmldoc.CreateElement("pagename");
                XmlElement Tipaddr = xmldoc.CreateElement("ipaddr");
                XmlElement Tdatetime = xmldoc.CreateElement("datetime");

                Tid.InnerText = id.ToString();
                Tuserid.InnerText = userid.ToString();
                Tlogtype.InnerText = LogType.ToString();
                Tlogmesg.InnerText = LogMsg.ToString();
                Tpagename.InnerText = PageName.ToString();
                Tipaddr.InnerText = IPAddress.ToString();
                Tdatetime.InnerText = System.DateTime.Now.ToString(string.Format("dd/MM/yyyy"));

                parentNode.AppendChild(Tid);
                parentNode.AppendChild(Tuserid);
                parentNode.AppendChild(Tlogtype);
                parentNode.AppendChild(Tlogmesg);
                parentNode.AppendChild(Tpagename);
                parentNode.AppendChild(Tipaddr);
                parentNode.AppendChild(Tdatetime);

                xmldoc.DocumentElement.AppendChild(parentNode);
                xmldoc.Save(FileNames);
            }
        }
    }
    //For Purchase Receive
    public void SetPurchaseOrderReceiveLogs(string id, string userid, string LogType, string LogMsg, string PageName, string IPAddress, string DateTime)
    {
        string date = System.DateTime.Now.ToString(string.Format("dd-MMM-yyyy"));
        string path = HttpContext.Current.Server.MapPath("~/XML/");
        string fileName = string.Empty;
        string FileNames = path + "Log_PurchaseOrderReceive_" + date + ".xml";
        DirectoryInfo dir = new DirectoryInfo(path);
        FileInfo[] fileList = dir.GetFiles("Log_PurchaseOrderReceive_*.xml", System.IO.SearchOption.AllDirectories);
        if (fileList.LongLength == 0)
        {
            XmlTextWriter xmlWriter = new XmlTextWriter(FileNames, System.Text.Encoding.UTF8);
            xmlWriter.Formatting = Formatting.Indented;
            xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
            xmlWriter.WriteStartElement("LogsDetails");
            xmlWriter.Close();

            XmlDocument xmldoc = new XmlDocument();
            //xmldoc.Load(Server.MapPath("~/XML/EmployeEdit" + DateTime.Now.ToShortDateString() + ".xml"));
            //xmldoc.Load("c:\\firstXML" + DateTime.Now.ToString(string.Format("dd-MMM-yyyy")) + ".xml");
            xmldoc.Load(FileNames);
            XmlElement parentNode = xmldoc.CreateElement("log");

            XmlElement Tid = xmldoc.CreateElement("id");
            XmlElement Tuserid = xmldoc.CreateElement("userid");
            XmlElement Tlogtype = xmldoc.CreateElement("logtype");
            XmlElement Tlogmesg = xmldoc.CreateElement("logmesg");
            XmlElement Tpagename = xmldoc.CreateElement("pagename");
            XmlElement Tipaddr = xmldoc.CreateElement("ipaddr");
            XmlElement Tdatetime = xmldoc.CreateElement("datetime");

            Tid.InnerText = id.ToString();
            Tuserid.InnerText = userid.ToString();
            Tlogtype.InnerText = LogType.ToString();
            Tlogmesg.InnerText = LogMsg.ToString();
            Tpagename.InnerText = PageName.ToString();
            Tipaddr.InnerText = IPAddress.ToString();
            Tdatetime.InnerText = System.DateTime.Now.ToString(string.Format("dd/MM/yyyy"));

            parentNode.AppendChild(Tid);
            parentNode.AppendChild(Tuserid);
            parentNode.AppendChild(Tlogtype);
            parentNode.AppendChild(Tlogmesg);
            parentNode.AppendChild(Tpagename);
            parentNode.AppendChild(Tipaddr);
            parentNode.AppendChild(Tdatetime);

            xmldoc.DocumentElement.AppendChild(parentNode);
            xmldoc.Save(FileNames);
        }
        else
        {
            var fileCount = from fileNew in fileList where fileNew.Name.Equals("Log_PurchaseOrderReceive_" + date + ".xml") select fileNew.Name;
            if (fileCount.Count() == 1)
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(FileNames);
                XmlElement parentNode = xmldoc.CreateElement("log");

                XmlElement Tid = xmldoc.CreateElement("id");
                XmlElement Tuserid = xmldoc.CreateElement("userid");
                XmlElement Tlogtype = xmldoc.CreateElement("logtype");
                XmlElement Tlogmesg = xmldoc.CreateElement("logmesg");
                XmlElement Tpagename = xmldoc.CreateElement("pagename");
                XmlElement Tipaddr = xmldoc.CreateElement("ipaddr");
                XmlElement Tdatetime = xmldoc.CreateElement("datetime");

                Tid.InnerText = id.ToString();
                Tuserid.InnerText = userid.ToString();
                Tlogtype.InnerText = LogType.ToString();
                Tlogmesg.InnerText = LogMsg.ToString();
                Tpagename.InnerText = PageName.ToString();
                Tipaddr.InnerText = IPAddress.ToString();
                Tdatetime.InnerText = System.DateTime.Now.ToString(string.Format("dd/MM/yyyy"));

                parentNode.AppendChild(Tid);
                parentNode.AppendChild(Tuserid);
                parentNode.AppendChild(Tlogtype);
                parentNode.AppendChild(Tlogmesg);
                parentNode.AppendChild(Tpagename);
                parentNode.AppendChild(Tipaddr);
                parentNode.AppendChild(Tdatetime);

                xmldoc.DocumentElement.AppendChild(parentNode);
                xmldoc.Save(FileNames);
            }
            else
            {
                XmlTextWriter xmlWriter = new XmlTextWriter(FileNames, System.Text.Encoding.UTF8);
                xmlWriter.Formatting = Formatting.Indented;
                xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
                xmlWriter.WriteStartElement("LogsDetails");
                xmlWriter.Close();

                XmlDocument xmldoc = new XmlDocument();
                //xmldoc.Load(Server.MapPath("~/XML/EmployeEdit" + DateTime.Now.ToShortDateString() + ".xml"));
                //xmldoc.Load("c:\\firstXML" + DateTime.Now.ToString(string.Format("dd-MMM-yyyy")) + ".xml");
                xmldoc.Load(FileNames);
                XmlElement parentNode = xmldoc.CreateElement("log");

                XmlElement Tid = xmldoc.CreateElement("id");
                //XmlAttribute attributeID = xmldoc.CreateAttribute("");
                XmlElement Tuserid = xmldoc.CreateElement("userid");
                XmlElement Tlogtype = xmldoc.CreateElement("logtype");
                XmlElement Tlogmesg = xmldoc.CreateElement("logmesg");
                XmlElement Tpagename = xmldoc.CreateElement("pagename");
                XmlElement Tipaddr = xmldoc.CreateElement("ipaddr");
                XmlElement Tdatetime = xmldoc.CreateElement("datetime");

                Tid.InnerText = id.ToString();
                Tuserid.InnerText = userid.ToString();
                Tlogtype.InnerText = LogType.ToString();
                Tlogmesg.InnerText = LogMsg.ToString();
                Tpagename.InnerText = PageName.ToString();
                Tipaddr.InnerText = IPAddress.ToString();
                Tdatetime.InnerText = System.DateTime.Now.ToString(string.Format("dd/MM/yyyy"));

                parentNode.AppendChild(Tid);
                parentNode.AppendChild(Tuserid);
                parentNode.AppendChild(Tlogtype);
                parentNode.AppendChild(Tlogmesg);
                parentNode.AppendChild(Tpagename);
                parentNode.AppendChild(Tipaddr);
                parentNode.AppendChild(Tdatetime);

                xmldoc.DocumentElement.AppendChild(parentNode);
                xmldoc.Save(FileNames);
            }
        }
    }
    //For OnlineRequestion,Issueitem,Backflush
    public void SetItemRequest_Issue(string id, string userid, string LogType, string LogMsg, string PageName, string IPAddress, string DateTime)
    {
        string date = System.DateTime.Now.ToString(string.Format("dd-MMM-yyyy"));
        string path = HttpContext.Current.Server.MapPath("~/XML/");
        string fileName = string.Empty;
        string FileNames = path + "Log_SetItemRequest_" + date + ".xml";
        DirectoryInfo dir = new DirectoryInfo(path);
        FileInfo[] fileList = dir.GetFiles("Log_SetItemRequest_*.xml", System.IO.SearchOption.AllDirectories);
        if (fileList.LongLength == 0)
        {
            XmlTextWriter xmlWriter = new XmlTextWriter(FileNames, System.Text.Encoding.UTF8);
            xmlWriter.Formatting = Formatting.Indented;
            xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
            xmlWriter.WriteStartElement("LogsDetails");
            xmlWriter.Close();

            XmlDocument xmldoc = new XmlDocument();
            //xmldoc.Load(Server.MapPath("~/XML/EmployeEdit" + DateTime.Now.ToShortDateString() + ".xml"));
            //xmldoc.Load("c:\\firstXML" + DateTime.Now.ToString(string.Format("dd-MMM-yyyy")) + ".xml");
            xmldoc.Load(FileNames);
            XmlElement parentNode = xmldoc.CreateElement("log");

            XmlElement Tid = xmldoc.CreateElement("id");
            XmlElement Tuserid = xmldoc.CreateElement("userid");
            XmlElement Tlogtype = xmldoc.CreateElement("logtype");
            XmlElement Tlogmesg = xmldoc.CreateElement("logmesg");
            XmlElement Tpagename = xmldoc.CreateElement("pagename");
            XmlElement Tipaddr = xmldoc.CreateElement("ipaddr");
            XmlElement Tdatetime = xmldoc.CreateElement("datetime");

            Tid.InnerText = id.ToString();
            Tuserid.InnerText = userid.ToString();
            Tlogtype.InnerText = LogType.ToString();
            Tlogmesg.InnerText = LogMsg.ToString();
            Tpagename.InnerText = PageName.ToString();
            Tipaddr.InnerText = IPAddress.ToString();
            Tdatetime.InnerText = System.DateTime.Now.ToString(string.Format("dd/MM/yyyy"));

            parentNode.AppendChild(Tid);
            parentNode.AppendChild(Tuserid);
            parentNode.AppendChild(Tlogtype);
            parentNode.AppendChild(Tlogmesg);
            parentNode.AppendChild(Tpagename);
            parentNode.AppendChild(Tipaddr);
            parentNode.AppendChild(Tdatetime);

            xmldoc.DocumentElement.AppendChild(parentNode);
            xmldoc.Save(FileNames);
        }
        else
        {
            var fileCount = from fileNew in fileList where fileNew.Name.Equals("Log_SetItemRequest_" + date + ".xml") select fileNew.Name;
            if (fileCount.Count() == 1)
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(FileNames);
                XmlElement parentNode = xmldoc.CreateElement("log");

                XmlElement Tid = xmldoc.CreateElement("id");
                XmlElement Tuserid = xmldoc.CreateElement("userid");
                XmlElement Tlogtype = xmldoc.CreateElement("logtype");
                XmlElement Tlogmesg = xmldoc.CreateElement("logmesg");
                XmlElement Tpagename = xmldoc.CreateElement("pagename");
                XmlElement Tipaddr = xmldoc.CreateElement("ipaddr");
                XmlElement Tdatetime = xmldoc.CreateElement("datetime");

                Tid.InnerText = id.ToString();
                Tuserid.InnerText = userid.ToString();
                Tlogtype.InnerText = LogType.ToString();
                Tlogmesg.InnerText = LogMsg.ToString();
                Tpagename.InnerText = PageName.ToString();
                Tipaddr.InnerText = IPAddress.ToString();
                Tdatetime.InnerText = System.DateTime.Now.ToString(string.Format("dd/MM/yyyy"));

                parentNode.AppendChild(Tid);
                parentNode.AppendChild(Tuserid);
                parentNode.AppendChild(Tlogtype);
                parentNode.AppendChild(Tlogmesg);
                parentNode.AppendChild(Tpagename);
                parentNode.AppendChild(Tipaddr);
                parentNode.AppendChild(Tdatetime);

                xmldoc.DocumentElement.AppendChild(parentNode);
                xmldoc.Save(FileNames);
            }
            else
            {
                XmlTextWriter xmlWriter = new XmlTextWriter(FileNames, System.Text.Encoding.UTF8);
                xmlWriter.Formatting = Formatting.Indented;
                xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
                xmlWriter.WriteStartElement("LogsDetails");
                xmlWriter.Close();

                XmlDocument xmldoc = new XmlDocument();
                //xmldoc.Load(Server.MapPath("~/XML/EmployeEdit" + DateTime.Now.ToShortDateString() + ".xml"));
                //xmldoc.Load("c:\\firstXML" + DateTime.Now.ToString(string.Format("dd-MMM-yyyy")) + ".xml");
                xmldoc.Load(FileNames);
                XmlElement parentNode = xmldoc.CreateElement("log");

                XmlElement Tid = xmldoc.CreateElement("id");
                //XmlAttribute attributeID = xmldoc.CreateAttribute("");
                XmlElement Tuserid = xmldoc.CreateElement("userid");
                XmlElement Tlogtype = xmldoc.CreateElement("logtype");
                XmlElement Tlogmesg = xmldoc.CreateElement("logmesg");
                XmlElement Tpagename = xmldoc.CreateElement("pagename");
                XmlElement Tipaddr = xmldoc.CreateElement("ipaddr");
                XmlElement Tdatetime = xmldoc.CreateElement("datetime");

                Tid.InnerText = id.ToString();
                Tuserid.InnerText = userid.ToString();
                Tlogtype.InnerText = LogType.ToString();
                Tlogmesg.InnerText = LogMsg.ToString();
                Tpagename.InnerText = PageName.ToString();
                Tipaddr.InnerText = IPAddress.ToString();
                Tdatetime.InnerText = System.DateTime.Now.ToString(string.Format("dd/MM/yyyy"));

                parentNode.AppendChild(Tid);
                parentNode.AppendChild(Tuserid);
                parentNode.AppendChild(Tlogtype);
                parentNode.AppendChild(Tlogmesg);
                parentNode.AppendChild(Tpagename);
                parentNode.AppendChild(Tipaddr);
                parentNode.AppendChild(Tdatetime);

                xmldoc.DocumentElement.AppendChild(parentNode);
                xmldoc.Save(FileNames);
            }
        }
    }  

    public  enum Type
    {
        ActivityLog,
        EventLog
    }   
}
